<?php

/**
 * @abstract 进行微信扫码支付
 * @author ran.ran
 * @example
 *public function actions()
    {
        return [
            'wxpay'=>
            [
                'class'=>'components\QrcodeWxpayAction',
               // 'notifyUrl'=>'http://www.baidu.com'
            ]

        ];
    }
 */
namespace components;

use Opwechat\Phppayment\NativePay;
use yii\helpers\Html;
use dosamigos\qrcode\QrCode;
use yii\base\Exception;
use Yii;
use yii\web\NotFoundHttpException;

class QrcodeWxpayAction extends BasePayMentAction
{
    public function run(){
      try{
         //验证
         $res = $this->validateOrderInfo();
         
         //用户已经支付及支付金额小于0 。跳转到详情页
         if(!$res['flag']) {
             $url = Yii::$app->urlManager->createUrl(['order-details/order-list']);
             return Yii::$app->response->redirect($url);
         }
         
        } catch(Exception $e){
            
           throw  new NotFoundHttpException();
        }
        
       $notify = new NativePay();
       
       $url = $notify->GetPrePayUrl($this->orderId);
       return Html::img(QrCode::png($url,false,'L',6,0));
    }
    
}

?>